// 完美
#include <bits/stdc++.h>
using namespace std;
int a[300005], up[300005];
int main() {
  int n;
  cin >> n;

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int m = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] > a[i - 1]) {
      up[m]++;
    } else if (up[m] != 0) {
      m++;
    }
  }
  for (int i = 2; i <= m; i++) {
    ans += 1LL * up[i] * up[i - 1];
  }
  cout << ans;
  return 0;
}